package com.wlyuan.open.domain.source.dispatcher.conversion;

import com.wlyuan.core.exception.AssertUtils;
import com.wlyuan.core.exception.ValueError;
import com.wlyuan.open.dto.OpenUserSyncDTO;
import com.wlyuan.open.utils.LongUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Service;

/**
 * @author lijing
 * @description
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class OpenDispatcherUserConversion implements OpenDispatcherConversion<OpenUserSyncDTO> {
    private final BaseOpenDispatcherConversion baseOpenDispatcherConversion;

    @Override
    public void convert(OpenUserSyncDTO source) {
        var tenant = source.getTenantId();
        if (LongUtils.notNullLong(tenant)) {
            Long tenantId = baseOpenDispatcherConversion.tenant(tenant);
            AssertUtils.assertNotNull(tenantId, new ValueError("OpenUserSyncDTO租户不存在:" + tenant), source);
            source.setTenantId(tenantId);
        }
    }
}
